package com.company;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Random;

public class PriorityQueueTest {

    public static void main(String[] args) {
        int[] test=new int[100];
        generate(test);
        Comparator<Integer> cmp=new Comparator<Integer>() {
            @Override
            public int compare(Integer integer, Integer t1) {
                return integer-t1;  //从小到大
            }
        };
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<Integer>(cmp);
        for(int i=0;i<test.length;i++){
            priorityQueue.add(test[i]);
        }
        while(!priorityQueue.isEmpty()){
            System.out.println(priorityQueue.poll());
        }
    }

    private static void generate(int[] test) {
        // 产生数据
        Random r = new Random();
        for(int i=0; i<test.length; i++){
            test[i] = r.nextInt(1000);
        }
    }
}
